package com.chenfwind.common;

import java.util.List;

public class ResultVO<T> {
	private Integer status;
	private String message;
	private Long resultCount;
	private Integer pageSize; //每页记录数
	private Integer pageCount;//总页数
	private Integer start;    //起始记录数
	private Long totalRecords;//总记录数
	private T result;
	private String sig;
	private int total;
	private T rows;
	
	public ResultVO(){}
	
	public ResultVO (Integer status , String message ,T result){
		this.status = status;
		this.message = message;
		this.result = result;
	}
	
	public static <T> ResultVO<T> create() {
		ResultVO<T> result = new ResultVO<T>();
		return result;
	}

	public static <T> ResultVO<T> create(Integer status) {
		ResultVO<T> result = new ResultVO<T>();
		result.setStatus(status);
		return result;
	}

	public static <T> ResultVO<T> create(Integer status, String message) {
		ResultVO<T> result = new ResultVO<T>();
		result.setStatus(status);
		result.setMessage(message);
		return result;
	}
	
	@SuppressWarnings("rawtypes")
	public void reCalcStatus() {
		if (result != null) {
			status = Constant.CODE_SUCCESS;
			//instanceof 运算符是用来在运行时指出对象是否是特定类的一个实例
			if (result instanceof List) {
				resultCount = (long) ((List) result).size();
			} else {
				resultCount = (long) 1;
			}
			pageCount = (pageCount == null || pageCount == 1) ? null : pageCount;
			if (totalRecords != null && resultCount != null) {
				totalRecords = (totalRecords == resultCount) ? null : totalRecords;
			}
		} else {
			status = Constant.CODE_NODATA;
		}
	}
	
	public Integer getStatus() {
		return status;
	}
	public void setStatus(Integer status) {
		this.status = status;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public Long getResultCount() {
		return resultCount;
	}
	public void setResultCount(Long resultCount) {
		this.resultCount = resultCount;
	}
	public Integer getPageSize() {
		return pageSize;
	}
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
	public Integer getPageCount() {
		return pageCount;
	}
	public void setPageCount(Integer pageCount) {
		this.pageCount = pageCount;
	}
	public Integer getStart() {
		return start;
	}
	public void setStart(Integer start) {
		this.start = start;
	}
	public Long getTotalRecords() {
		return totalRecords;
	}
	public void setTotalRecords(Long totalRecords) {
		this.totalRecords = totalRecords;
	}
	public T getResult() {
		return result;
	}
	public void setResult(T result) {
		this.result = result;
	}
	public String getSig() {
		return sig;
	}
	public void setSig(String sig) {
		this.sig = sig;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public T getRows() {
		return rows;
	}

	public void setRows(T rows) {
		this.rows = rows;
	}

	
	
	
}
